package com.fly.lambda.framework.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;

/**
 * Created by Fly on 2016/7/14.
 */
public class CommonUtils {

    /**
     * 生成32位UUID
     * @return
     */
    public static String genPK(){
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 日期相加
     * @param date
     * @param field
     * @param amount
     * @return
     */
    public static Date dateAdd(Date date, int field, int amount){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(field, amount);
        return calendar.getTime();
    }

    /**
     * 日期转字符串
     * @param date
     * @param format
     * @return
     */
    public static String dateToStr(Date date, String format){
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}
